import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class LineNumberingTextFile {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = null;
		FileWriter writer = null;
		try {
			reader = new BufferedReader(new FileReader("some-file.txt"));
			writer = new FileWriter("numbered-lines.txt");
			insertLineNumbers(reader, writer);
		} finally {
			if (writer != null)
				writer.close();
			if (reader != null)
				reader.close();
		}
	}

	private static void insertLineNumbers(BufferedReader reader,
			FileWriter writer) throws IOException {
		int lineNumber = 0;
		while (true) {
			String line = reader.readLine();
			if (line == null) {
				break;
			}
			lineNumber++;
			writer.write(lineNumber + ". " + line + "\n");
		}
	}
}
